<?php
class KqsController extends AppController {

	var $name = 'Kqs';
	var $helpers=array('Ctable','Html','Form','Js','Session');
	var $uses=array('Kq');

	function index($dulieu) {
		//$dulieu=10002;
		$this->Cookie->write('D',$dulieu);
		$this->Kq->recursive = 0;
		$this->set('kqs', $this->paginate());
	}
	function nhaplieu(){

		
	}

	function view($id = null) {
		$d=$this->Cookie->read('D');
		print_r($d);
		if (!$id) {
			$this->Session->setFlash(__('Invalid kq', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('kq', $this->Kq->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Kq->create();
			if ($this->Kq->save($this->data)) {
				$this->Session->setFlash(__('The kq has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The kq could not be saved. Please, try again.', true));
			}
		}
		$ps = $this->Kq->P->find('list');
		$chiphis = $this->Kq->Chiphi->find('list');
		$noidungs = $this->Kq->Noidung->find('list');
		$this->set(compact('ps', 'chiphis', 'noidungs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid kq', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Kq->save($this->data)) {
				$this->Session->setFlash(__('The kq has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The kq could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Kq->read(null, $id);
		}
		$ps = $this->Kq->P->find('list');
		$chiphis = $this->Kq->Chiphi->find('list');
		$noidungs = $this->Kq->Noidung->find('list');
		$this->set(compact('ps', 'chiphis', 'noidungs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for kq', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Kq->delete($id)) {
			$this->Session->setFlash(__('Kq deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Kq was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
